package com.admin.business.background.venusOaNotice;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 通知公告表
 * @create: 2023-11-01 09:27:46
 **/
@Service("venusOaNoticeService")
@Slf4j
public class VenusOaNoticeService{

    @Resource
    VenusOaNoticeDao venusOaNoticeDao;

    /**
     * 添加通知公告表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:用户id
     *                   - org_id:公司id
     *                   - project_id:项目id
     *                   - notice_name:通知公告名称
     *                   - notice_type_id:通知公告分类id
     *                   - notice_release_time:通知公告发布时间
     *                   - notice_invalid_time:通知公告失效时间
     *                   - notice_type:通知公告类型(1.普通通知，2.紧急通知)
     *                   - notice_website_display:通知公告官方展示(1.是，2.否)
     *                   - forwardObject:转发对象
     *                   - notice_scope:通知公告通知范围(1.员工，2.业主，3.业态, 4欠费业主)
     *                   - notice_staff_org_id:员工范围 公司id
     *                   - notice_staff_department_id:员工范围 部门id
     *                   - notice_staff_post_id:员工范围 岗位id
     *                   - notice_owner_project_id:业主范围 项目id
     *                   - notice_owner_areanumber:业主范围 区号
     *                   - notice_owner_floornumber:业主范围 楼号
     *                   - notice_owner_unitnumber:业主范围 单元号
     *                   - notice_owner_doornumber:业主范围 门牌号
     *                   - notice_format_project_id:业态范围 项目id
     *                   - notice_format_room_id:业态范围 房屋性质
     *                   - notice_content:通知公告内容
     *                   - notice_image:通知公告图片
     *                   - notice_readnumber:通知公告已读数量
     *                   - notice_cancel_user_id:作废人员id
     *                   - notice_cancel_content:作废原因
     *                   - notice_time:作废时间
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author Ht
     * @create: 2023-11-01 09:27:46
     */
    @OpenApi
    public Return addVenusOaNotice(CDO cdoRequest) {
        venusOaNoticeDao.addVenusOaNotice(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新通知公告表数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:用户id
     *                   - org_id:公司id
     *                   - project_id:项目id
     *                   - notice_name:通知公告名称
     *                   - notice_type_id:通知公告分类id
     *                   - notice_release_time:通知公告发布时间
     *                   - notice_invalid_time:通知公告失效时间
     *                   - notice_type:通知公告类型(1.普通通知，2.紧急通知)
     *                   - notice_website_display:通知公告官方展示(1.是，2.否)
     *                   - forwardObject:转发对象
     *                   - notice_scope:通知公告通知范围(1.员工，2.业主，3.业态, 4欠费业主)
     *                   - notice_staff_org_id:员工范围 公司id
     *                   - notice_staff_department_id:员工范围 部门id
     *                   - notice_staff_post_id:员工范围 岗位id
     *                   - notice_owner_project_id:业主范围 项目id
     *                   - notice_owner_areanumber:业主范围 区号
     *                   - notice_owner_floornumber:业主范围 楼号
     *                   - notice_owner_unitnumber:业主范围 单元号
     *                   - notice_owner_doornumber:业主范围 门牌号
     *                   - notice_format_project_id:业态范围 项目id
     *                   - notice_format_room_id:业态范围 房屋性质
     *                   - notice_content:通知公告内容
     *                   - notice_image:通知公告图片
     *                   - notice_readnumber:通知公告已读数量
     *                   - notice_cancel_user_id:作废人员id
     *                   - notice_cancel_content:作废原因
     *                   - notice_time:作废时间
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author Ht
     * @create: 2023-11-01 09:27:46
     */
    @OpenApi
    public Return updateVenusOaNoticeById(CDO cdoRequest) {
        venusOaNoticeDao.updateVenusOaNoticeById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除通知公告表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-01 09:27:46
     */
    @OpenApi
    public Return deleteVenusOaNoticeById(CDO cdoRequest){
        int count = venusOaNoticeDao.deleteVenusOaNoticeById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除通知公告表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-01 09:27:46
     */
    @OpenApi
    public Return deleteVenusOaNotice(CDO cdoRequest) {
        int count = venusOaNoticeDao.deleteVenusOaNotice(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取通知公告表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-01 09:27:46
     */
    @OpenApi
    public Return getVenusOaNoticeById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaNoticeDao.getVenusOaNoticeById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取通知公告表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-01 09:27:46
     */
    @OpenApi
    public Return getVenusOaNoticeListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaNoticeDao.getVenusOaNoticeListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaNoticeDao.getVenusOaNoticeCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取通知公告表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-01 09:27:46
     */
    @OpenApi
    public Return getVenusOaNoticeListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaNoticeDao.getVenusOaNoticeListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaNoticeDao.getVenusOaNoticeCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
